package com.ccrfid.rmc6.repository.personnel;

import com.ccrfid.rmc6.entity.personnel.PersonnelVitalSignsAlarmConfigEntity;
import com.ccrfid.rmc6.repository.search.SearchableRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;

public interface PersonnelVitalSignsAlarmConfigRepository extends Repository<PersonnelVitalSignsAlarmConfigEntity, Long>, SearchableRepository<PersonnelVitalSignsAlarmConfigEntity> {

    /**
     * 新增人员生命体征预警配置
     * @param entity
     * @return
     */
    PersonnelVitalSignsAlarmConfigEntity save(PersonnelVitalSignsAlarmConfigEntity entity);

    /**
     * 判断该人员id是否存在
     * @param personnelId
     * @return
     */
    Boolean existsByPersonnelId(Long personnelId);

    /**
     * 删除人员配置信息
     * @param personnelId
     */
    @Transactional
    @Modifying
    @Query(nativeQuery = true, value = "delete from personnel_vital_signs_alarm_config where personnel_id = :personnelId")
    void deleteByPersonnelId(@Param("personnelId") Long personnelId);

    /**
     * 根据personnelId获取配置信息
     * @param personId
     * @return
     */
    PersonnelVitalSignsAlarmConfigEntity getByPersonnelId(Long personId);

}
